package JSON;

import com.alibaba.fastjson2.JSON;
import org.junit.Test;
/*
*   fastjson2实现JSON和java对象的转换
*       JSON.toJSONString()  所有类型的java对象转换为json格式
*       JSON.toJSONString(obj,JSONWriter.Feature.PrettyFormat)  java对象转换为json格式,并格式化
*
*       JSON.parseObject(str,字节码对象)  json格式转换为java对象
*       JSONArray.parseArray(str,字节码对象)  解析数组形式的JSON字符串,并转换为指定类型的List集合
* */
public class fastjsonTest {
    @Test
    public void test01() {
        Student student = new Student("张三", 18, "男");
        System.out.println(JSON.toJSONString(student));
    }
    @Test
    public void test02() {
        String jsonStr = "{\"name\":\"张三\",\"age\":18,\"gender\":\"男\"}";
        Student student = JSON.parseObject(jsonStr, Student.class);
        System.out.println(student);
    }
    public static void main(String[] args) {
        String jsonStr = "[{\"name\":\"张三\",\"age\":18,\"gender\":\"男\"},{\"name\":\"李四\",\"age\":19,\"gender\":\"女\"}]";

    }
}
